package component;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;

import java.beans.PropertyDescriptor;

/**
 * @author: ZhouBert
 * @date: 2020/9/22
 * @description:	测试：自定义 InstantiationAwareBeanPostProcessor 重写 postProcessPropertyValues
 */
public class MyInstantiationAwareBeanPostProcessor4PostProcessPropertyValues implements InstantiationAwareBeanPostProcessor {

	public static final String SPECIFIC_NAME = "noPopulateBeanConfig";

	@Override
	public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {
		if (beanName.equals(SPECIFIC_NAME)) {
			for (PropertyDescriptor descriptor :
					pds) {
				System.out.println("descriptor = " + descriptor);
			}
			// 如果返回 null 就会中止其他 InstantiationAwareBeanPostProcessor 的 postProcessPropertyValues 去处理注入属性
			// eg.下面几个：
			//	1.ConfigurationClassPostProcessor -> setBeanFactory
			//  2.CommonAnnotationBeanPostProcessor -> 获取 InjectionMetadata，
			// 		处理 CommonAnnotationBeanPostProcessor 缓存的注解（i.e.@PostConstruct @PreDestroy）
			//  3.AutowiredAnnotationBeanPostProcessor -> 获取 InjectionMetadata，
			//		处理 AutowiredAnnotationBeanPostProcessor 的缓存的注解（i.e.@Autowired @Value）
			return null;
		}
		return pvs;
	}
}
